/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.instructional.example.swing;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;

import javax.swing.JButton;

public class J42JButton_02 extends JButton {

    private static final long serialVersionUID = -42L;

    public J42JButton_02(final String string) {
        super(string);
        setOpaque(false);
        setBackground(new Color(0, 0, 0, 0));
        setForeground(new Color(0, 0, 0, 255));
    }

    @Override
    protected void paintComponent(final Graphics g) {
        final Graphics2D g2d = (Graphics2D) g;
        final int R = getBackground().getRed();
        final int G = getBackground().getGreen();
        final int B = getBackground().getBlue();
        final int A = getBackground().getAlpha();
        final Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, A), 0.0f, getHeight(), new Color(R, G, B, 255 - A), true);
        g2d.setPaint(p);
        g2d.fillRect(0, 0, getWidth(), getHeight());
        super.paintComponent(g);
    }

}
